package cn.wyl.controller;

import cn.wyl.dto.BuyDto;
import cn.wyl.feignclient.BuyFeignClient;
import cn.wyl.service.IBuyLogService;
import cn.wyl.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ByuLogController {

    @Autowired
    private BuyFeignClient buyFeignClient;

    @Autowired
    private IBuyLogService buyLogService;

    @PostMapping("/buy")
    public AjaxResult save(@RequestBody BuyDto buyDto){
        try {
            System.out.println(buyDto);
            return buyLogService.save(buyDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error().setMessage(e.getMessage());
        }
    }

    @GetMapping("/buy/getCourseById/{id}")
    public AjaxResult getCourseById(@PathVariable("id") Long id){
        return buyFeignClient.findById(id);
    }

}
